<?php
include('connect.php');

if($_GET['from_id']>0) $from_id = $_GET['from_id'];

if($_POST['from_id']>0) $from_id = $_POST['from_id'];

if($_GET['to_id']>0) $to_id = $_GET['to_id'];

if($_POST['to_id']>0) $to_id = $_POST['to_id'];


if($_POST['to_id']>0)
{
   $sq = 'insert into chat_message set from_id='.$from_id.', to_id='.$to_id.', content="'.$_POST['content'].'"';
   
   mysql_query($sq);
}



$sql = "select sf_guard_user.nickname, from_id, to_id, content from sf_guard_user, chat_message where sf_guard_user.id=chat_message.from_id and ((from_id=".$from_id.' and to_id='.$to_id.") or (from_id=".$to_id." and to_id=".$from_id.'))' ;

$rez = mysql_query($sql);
$str = '<table>';
while(list($nick, $from_id,$to_id,$content)=mysql_fetch_row($rez))
{

   $str.='<tr><td><b>'.$nick.'</b>:&nbsp;&nbsp;</td><td>'.nl2br($content).'</td></tr>';
}
$str .= '</table>';
echo $str;
?>